﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsGame1.CoreComponents;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace WindowsGame1
{
    class IntroScreen : GameScreen
    {
        Texture2D introduction;

        TimeSpan myTimeSpan;
        Vector2 position;

        bool fadeFinished = false;
        bool topReached = false;

        byte alphaValue = 254;

        Color tintColor = Color.White;
        Texture2D background;

        public IntroScreen(Game1 game)
            : base(game)
        {
            LoadContent();
            Components.Add(new BackgroundComponent(game, background, true));
            position = new Vector2(0, Game.Window.ClientBounds.Height);
        }

        protected override void LoadContent()
        {
            background = Content.Load<Texture2D>(@"Backgrounds\introbackground");
            introduction = Content.Load<Texture2D>(@"Backgrounds\introduction");
            base.LoadContent();
        }

        public bool IntroFinished
        {
            get { return fadeFinished; }
        }

        public override void Update(GameTime gameTime)
        {
            myTimeSpan += gameTime.ElapsedGameTime;
            if (myTimeSpan > TimeSpan.FromMilliseconds(25) && !topReached)
            {
                position.Y -= 2.0f;
                myTimeSpan -= TimeSpan.FromMilliseconds(25);
                if (position.Y < 0.0f)
                {
                    position.Y = 0.0f;
                    topReached = true;
                }
            }
            if (myTimeSpan > TimeSpan.FromMilliseconds(15) && topReached)
            {
                if (alphaValue > 0)
                    alphaValue--;
                else
                    fadeFinished = true;
                tintColor.A = alphaValue;
                myTimeSpan -= TimeSpan.FromMilliseconds(15);
            }
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            spriteBatch.Draw(introduction, position, tintColor);
        }
    }
}